//
//  TT_IMManager.m
//  BaseProject
//
//  Created by 王洋 on 2020/4/28.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "TT_IMManager.h"

@interface TT_IMManager ()<TIMMessageListener>

@end

@implementation TT_IMManager

+ (instancetype)sharedInstance {
    static TT_IMManager * sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [TT_IMManager new];

    });
    return sharedInstance;
}

- (void)TTIM_InitSDK {
    
    [[TUIKit sharedInstance] setupWithAppId:1400360457 logLevel:TIM_LOG_NONE]; // SDKAppID 可以在 即时通信 IM 控制台中获取

}

- (int)TTIM_Login:(TIMLoginParam*)param succ:(TIMLoginSucc)succ fail:(TIMFail)fail {
    
    return [[TIMManager sharedInstance] login:param succ:succ fail:fail];
}

- (int)TTIM_GetUnreadMsgCount {
    
    //获取未读计数
    int unReadCount = 0;
    NSArray *convs = [[TIMManager sharedInstance] getConversationList];
    for (TIMConversation *conv in convs) {
        if([conv getType] == TIM_SYSTEM){
            continue;
        }
        unReadCount += [conv getUnReadMessageNum];
    }
    return unReadCount;
}

- (int)TTIM_LogOut:(TIMLoginSucc)succ fail:(TIMFail)fail {
    return [[TIMManager sharedInstance] logout:succ fail:fail];
}


- (void)TTIM_JoinGrop:(NSString *)groupId msg:(NSString*)msg succ:(TIMSucc)succ fail:(TIMFail)fail {
    [[TIMGroupManager sharedInstance] joinGroup:groupId msg:msg succ:succ fail:fail];
}


- (void)TTIM_GetGroupMenberList:(NSString*)groupId succ:(TIMGroupMemberSucc)succ fail:(TIMFail)fail {
    [[TIMGroupManager sharedInstance] getGroupMembers:groupId succ:succ fail:fail];
}


- (void)TTIM_QuitGroup:(NSString*)groupId succ:(TIMSucc)succ fail:(TIMFail)fail {
    [[TIMGroupManager sharedInstance] quitGroup:groupId succ:succ fail:fail];
}

- (void)TTIM_DeleteGroupConversation:(NSString*)groupId {
    
    [[TIMManager sharedInstance] deleteConversation:TIM_GROUP receiver:groupId];
}

- (void)TTIM_DeleteConversationAndMessages:(NSString*)groupId {
    
    [[TIMManager sharedInstance] deleteConversationAndMessages:TIM_GROUP receiver:groupId];
}

- (void)TTIM_GetSelfProfile:(TIMGetProfileSucc)succ fail:(TIMFail)fail {
    [[TIMFriendshipManager sharedInstance] getSelfProfile:succ fail:fail];
}

- (void)TTIM_GetUserProfile:(NSArray<NSString *> *)identifiers forceUpdate:(BOOL)forceUpdate succ:(TIMUserProfileArraySucc)succ fail:(TIMFail)fail {
    [[TIMFriendshipManager sharedInstance] getUsersProfile:identifiers forceUpdate:forceUpdate succ:succ fail:fail];
}

- (void)TTIM_SetSelfProfile:(NSDictionary *)dic succ:(TIMSucc)succ fail:(TIMFail)fail {
    /*
     TIMProfileTypeKey_Nick    NSString    昵称
     TIMProfileTypeKey_FaceUrl    NSString    头像
     TIMProfileTypeKey_AllowType    NSNumber    好友申请
     TIMProfileTypeKey_Gender    NSNumber    性别
     TIMProfileTypeKey_Birthday    NSNumber    生日
     TIMProfileTypeKey_Location    NSString    位置
     TIMProfileTypeKey_Language    NSNumber    语言
     TIMProfileTypeKey_Level    NSNumber    等级
     TIMProfileTypeKey_Role    NSNumber    角色
     TIMProfileTypeKey_SelfSignature    NSString    签名
     TIMProfileTypeKey_Custom_Prefix    NSString、NSData 或 NSNumber    自定义字段前缀
     */
    
    [[TIMFriendshipManager sharedInstance] modifySelfProfile:dic succ:succ fail:fail];
//    [[TIMFriendshipManager sharedInstance] modifySelfProfile:dic succ:succ fail:fail];
}

@end
